/************************************************************************************
* Title: main_analysis.do
* Created by: Jac M. Larner
* Created on: 22/07/2021
* Last modified on: 14/06/24
* Last modified by: Jac Larner
* Purpose: This .do file allows for replication of analysis for the paper "Vulnerability Appeals in the COVID-19 Pandemic: Insights from a National Survey Experiment" by Jac M. Larner and Joshua R. Thorp

*************************************************************************************/

clear all
set more off
set scheme s1mono

*Set your directory
cd "CHANGE HERE"

*Start a log file

log using "log_JEPS.log", text append

****************************************************************************************

* Figure 1 (Main body)

import delimited "Appeals_sum.csv", clear
graph bar appeals_sum, over(category) ytitle("Number of appeals")

* Load survey data
use "WES_2021_panel.dta", clear

* Figure 1 (appendix)
graph hbar (percent) [pw=w3_W8], over(w3_grid_a)  title("Masks compulsory") blabel(inside, format(%9.1f))
graph save "Graph" "a.gph", replace
graph hbar (percent) [pw=w3_W8], over(w3_grid_b)  title("Sacrifice freedoms") blabel(inside, format(%9.1f))
graph save "Graph" "b.gph", replace
graph hbar (percent) [pw=w3_W8], over(w3_grid_c)  title("No more lockdowns") blabel(inside, format(%9.1f))
graph save "Graph" "c.gph", replace
graph hbar (percent) [pw=w3_W8], over(w3_grid_d)  title("Concerned") blabel(inside, format(%9.1f))
graph save "Graph" "d.gph", replace
graph hbar (percent) [pw=w3_W8], over(w3_grid_e)  title("Anger") blabel(inside, format(%9.1f))
graph save "Graph" "e.gph", replace
graph hbar (percent) [pw=w3_W8], over(w3_grid_f)  title("Moved") blabel(inside, format(%9.1f))
graph save "Graph" "f.gph", replace
graph combine "a.gph" "b.gph" "c.gph" "d.gph" "e.gph" "f.gph", col(2)

 
********* Main Analysis (H1-H5)***********

*Code & label treatment variable
rename w3_splitJac treatment
label define treatment_lab 1 "Control" 2 "Disability treatment" 3 "Ethnic Min treatment" 4 "Combined treatment"
label values treatment treatment_lab
tab treatment

* Recode DKs in the outcome variable to missing
recode w3_grid_a w3_grid_b w3_grid_c w3_grid_d w3_grid_e w3_grid_f (6=.)

* Flip the coding so higher number = more likely to agree (more intuitive interpretation)
vreverse w3_grid_a, gen(w3_grid_a1)
vreverse w3_grid_b, gen(w3_grid_b1)
vreverse w3_grid_c, gen(w3_grid_c1)
vreverse w3_grid_d, gen(w3_grid_d1)
vreverse w3_grid_e, gen(w3_grid_e1)
vreverse w3_grid_f, gen(w3_grid_f1)

*Standardise outcome variables between 0-1
foreach var in w3_grid_a1 w3_grid_b1 w3_grid_c1 w3_grid_c w3_grid_d1 w3_grid_e1 w3_grid_f1 {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}
				
* Models to test Hypotheses 1-5
eststo m1: reg w3_grid_a1 i.treatment [pw=w3_W8], robust
eststo m2: reg w3_grid_b1 i.treatment [pw=w3_W8], robust
eststo m3: reg w3_grid_c1 i.treatment [pw=w3_W8], robust
eststo m4: reg w3_grid_d1 i.treatment [pw=w3_W8], robust
eststo m5: reg w3_grid_e1 i.treatment [pw=w3_W8], robust
eststo m6: reg w3_grid_f1 i.treatment [pw=w3_W8], robust

* Table 5 (appendix)
esttab m1 m2 m3 m4 m5 m6 using "Table5.tex", r2 se star(* 0.10 ** 0.05 *** 0.01) b(%9.3f) label


********* Create indices of affective and prosocial items *********

* Correlation table of items  for Table 3 and 4 in appendix (not using reverse coding for w3_grid_c for consistency in positive/negative direction)
correlate w3_grid_a1 w3_grid_b1 w3_grid_c
correlate w3_grid_d1 w3_grid_e1 w3_grid_f1

* Generate index for pro-social items
factor w3_grid_a1 w3_grid_b1 w3_grid_c
predict prosocial_index

* Generate index for affective items
factor w3_grid_d1 w3_grid_e1 w3_grid_f1
predict affective_index

*** Create Figure 2 for appendix ***
*Figure 2a 
twoway histogram prosocial_index, percent title("Distribution of Prosocial index")
*Figure 2b
twoway histogram affective_index, percent title("Distribution of Affective index")

*Standardise indices between 0-1
foreach var in prosocial_index affective_index {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')
		}

* Table 6 (appendix)
eststo m7: reg prosocial_index i.treatment [pw=w3_W8], robust
eststo m8: reg affective_index i.treatment [pw=w3_W8], robust
esttab m7 m8 using "Table6.tex", r2 se star(* 0.10 ** 0.05 *** 0.01) b(%9.3f) label

* Figure 3
coefplot m1, bylabel(Masks compulsory) ///
      || m4, bylabel(Concerned)  ///
      || m2, bylabel(Sacrifice freedoms)  ///
	  || m5, bylabel(Anger)  ///
	  || m3, bylabel(No more lockdowns)  ///
	  || m6, bylabel(Moved)  ///
	  || m7, bylabel(Prosocial index)  ///
	  || m8, bylabel(Affective index)  ///
      ||, drop(_cons) levels(99 95) xline(0, lcolor(red) lpattern(dash) ) xtitle("Coefficient") mlabel format(%9.2g) mlabposition(12) mlabgap(*2) 

	  
* Testing H6

*Gen variable that just looks at disability treatment and control
gen group1=.
replace group1=0 if treatment==1
replace group1=1 if treatment==2

*Generate dummy variable for respondent disabled
gen r_disab=.
replace r_disab=1 if w1_disability==1
replace r_disab=0 if w1_disability==2

*Generate dummy variable for respondent family member disabled
gen proxim_disab=.
replace proxim_disab=1 if w1_familymember==1
replace proxim_disab=0 if w1_familymember==2

* Table 7 (appendix)
eststo m13: reg w3_grid_a1 i.group1##r_disab [pw=w3_W8], robust
eststo m14: reg w3_grid_b1 i.group1##r_disab [pw=w3_W8], robust
quietly eststo m15: reg w3_grid_c1 i.group1##r_disab [pw=w3_W8], robust
quietly eststo m16: reg w3_grid_d1 i.group1##r_disab [pw=w3_W8], robust
quietly eststo m17: reg w3_grid_e1 i.group1##r_disab [pw=w3_W8], robust
quietly eststo m18: reg w3_grid_f1 i.group1##r_disab [pw=w3_W8], robust
quietly eststo m19: reg prosocial_index i.group1##r_disab [pw=w3_W8], robust
quietly eststo m20: reg affective_index i.group1##r_disab [pw=w3_W8], robust
esttab m13 m14 m15 m16 m17 m18 m19 m20 using "Table4.tex", r2 se star(* 0.10 ** 0.05 *** 0.01) b(%9.3f) label


* Figure 4
coefplot m13, bylabel(Masks compulsory) ///
      || m16, bylabel(Concerned)  ///
      || m14, bylabel(Sacrifice freedoms)  ///
	  || m17, bylabel(Anger)  ///
	  || m15, bylabel(No more lockdowns)  ///
	  || m18, bylabel(Moved)  ///
	  || m19, bylabel(Prosocial index)  ///
	  || m20, bylabel(Affective index)  ///
      ||, drop(_cons) levels(99, 95) xline(0, lcolor(red) lpattern(dash) )xtitle("Coefficient") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)   	  
	  
	  
* Table 8 (appendix)
quietly eststo m21: reg w3_grid_a1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m22: reg w3_grid_b1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m23: reg w3_grid_c1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m24: reg w3_grid_d1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m25: reg w3_grid_e1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m26: reg w3_grid_f1 i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m27: reg prosocial_index i.group1##proxim_disab [pw=w3_W8], robust
quietly eststo m28: reg affective_index i.group1##proxim_disab [pw=w3_W8], robust
esttab m21 m22 m23 m24 m25 m26 m27 m28 using "Table5.tex", r2 se star(* 0.10 ** 0.05 *** 0.01) b(%9.3f) label


****************************************************************************************

log close 
